package realQuestion.mi;

import java.sql.Array;
import java.util.ArrayList;

public class Test1 {

    public  int  test(int n){
        if (n==0){
            System.out.println("传入的参数不合法");
             return 0;
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i <=n; i++) {
            list.add(i);
        }
        int i=1;
        int j=0;
        int count= list.size();
        while (count>1){
            if (j>=count){
                j=0;
            }

            if ((i)%3==0){
                list.remove(j);
                j-=1;
                count= list.size();
            }

            i++;
            j++;
        }
        return list.get(0);
    }

    public static void main(String[] args) {
        System.out.println(new Test1().test(3));

    }
}
